Apple, the Apple logo, and Macintosh are registered trademarks of Apple Computer, Inc.
Mac and OpenDoc are trademarks of Apple Computer, Inc.
Using Factory Methods
OpenDoc provides factory methods to create many OpenDoc objects (ODPart, ODDraft, ODWindow). The factory methods are associated with the factory objects. For example, the factory object of all persistent objects (ODPart, ODFrame, ODLink etc) is ODDraft.
Clients of OpenDoc MUST use these factory methods to create the desired OpenDoc objects.
The main reason for using factory methods is for object distribution. Factory object ensures objects are created in the desired process. It also ensures that an object is instantiated correctly before it is being returned for use by clients.
Creating your own objects for OpenDoc
There are situations where a client of OpenDoc needs to create its own OpenDoc object (i.e., an object whose class is a subclass of ODObject and is defined by the client). Typically these objects are created by a shell plugin (ODDispatchModule, ODFocusModule and other ODObject subclasses).
For those cases, the client needs to use the OpenDoc utility call ODNewObject. The call can be found in ODNewObj.h and ODNewObj.cpp. (For more information on the method, please refer to the utility documentation.)
Sample Code
The following code fragment is taken from ScriptRunner shell plug-in sample code. What this shell plug-in does is creating an object to be installed in the namespace.
OpenDoc supports library unloading. That means when there is no outstanding object for a certain OpenDoc part editor, the part editor library is going to be unloaded. When the part editor is unloaded, all its imported libraries whose only connections are to the part library are also unloaded.
Suppose class A and part class P are in the same code fragment and object a (of class A) is created by part p (of class P). When p is deleted and its library gets unloaded, object a will become invalid also because its library (which is the library for P) is unloaded.
ODNewObject has special code to prevent a library from being unloaded when the input object is still outstanding.